package crazy;

public class InsertSort
{

	public static void main(String[] args)
	{
		DataWrap[] data = { new DataWrap(21, ""), new DataWrap(30, ""),
				new DataWrap(49, ""), new DataWrap(30, "*"),
				new DataWrap(16, ""), new DataWrap(9, "") };
		
		System.out.println("before sorting-->"+java.util.Arrays.toString(data));
		insertSort(data);
		System.out.println("after sorting-->"+java.util.Arrays.toString(data));
	}

	public static void insertSort(DataWrap[] data)
	{
		int arrayLength = data.length;
		for (int i = 1; i < arrayLength; i++)
		{
			DataWrap tmp = data[i];
			if (data[i].compareTo(data[i-1])<0)
			{
				int j = i -1;
				for (; j >=0 && data[j].compareTo(tmp)>0; j--)
				{
					System.out.println("j-->"+j);
					data[j+1] = data[j];
					System.out.println("data[j+1]-->"+data[j+1].toString());
				}
				data[j+1]=tmp;
				
				System.out.println("sss-->j="+j+"  "+data[j+1].toString());
			}
			System.out.println(java.util.Arrays.toString(data));
		}
	}
}
